const server = require('http').createServer()
const io = require('socket.io')(server, { cors: true })

io.on('connection', function (client) {

  console.log('client connected...', client.id)

  const handleSendQuestionUpdate = function () {
    console.log("客户端发来消息");
    client.broadcast.emit('getQuestionUpdate');
  }

  const handlesendCommunicateUpdate = function () {
    console.log("客户端发来消息");
    client.broadcast.emit('getCommunicateUpdate');
  }

  client.on('sendQuestionUpdate', handleSendQuestionUpdate)

  client.on('sendCommunicateUpdate', handlesendCommunicateUpdate)

  client.on('disconnect', function () {
    console.log('client disconnect...', client.id)
  })


})

server.listen(3000, function (err) {
  if (err) throw err
  console.log('listening on port 3000')
})
